package com.xinzhi.config;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.region.Region;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/// 配置腾讯云对象存储服务的客户端
@Configuration
public class CosConfig {
    @Value("${tencent.cos.secretId}")
    private String secretId;

    @Value("${tencent.cos.secretKey}")
    private String secretKey;
    @Value("${tencent.cos.region}")
    private String region;
    @Bean
    public COSClient cosClient() {
        // 设置COS客户端的认证信息
        COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
        // 设置COS客户端的配置信息
        ClientConfig clientConfig = new ClientConfig(new Region(region));
        // 创建COS客户端实例
        return new COSClient(cred, clientConfig);
    }
}
